home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue63 / Alfresco / TstExMgU.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2000-10-08  |  1.9 KB  |  99 lines

  1. unit TstExMgU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     Label1: TLabel;
  13.     Label2: TLabel;
  14.     procedure Button1Click(Sender: TObject);
  15.   private
  16.     { Private declarations }
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.DFM}
  27.  
  28. uses
  29.   AAExtMge;
  30.  
  31. const
  32.   MyRecCount = 400000;
  33.   MyRecLen = 64;
  34.  
  35. function MyCompare(const aItem1, aItem2 : pointer) : integer;
  36. var
  37.   Item1 : PByteArray;
  38.   Item2 : PByteArray;
  39.   i     : integer;
  40. begin
  41.   Item1 := aItem1;
  42.   Item2 := aItem2;
  43.   for i := 0 to pred(MyRecLen) do begin
  44.     if Item1^[i] < Item2^[i] then begin
  45.       Result := -1;
  46.       Exit;
  47.     end;
  48.     if Item1^[i] > Item2^[i] then begin
  49.       Result := 1;
  50.       Exit;
  51.     end;
  52.   end;
  53.   Result := 0;
  54. end;
  55.  
  56. procedure CreateInputFile;
  57. var
  58.   S : TFileStream;
  59.   i, j : integer;
  60.   Buffer : array [0..pred(MyRecLen)] of byte;
  61. begin
  62.   S := TFileStream.Create('C:\unsorted.dat', fmCreate);
  63.   try
  64.     for i := 1 to MyRecCount do begin
  65.       for j := 0 to MyRecLen-3 do
  66.         Buffer[j] := Random(26) + ord('A');
  67.       Buffer[MyRecLen-2] := 13;
  68.       Buffer[MyRecLen-1] := 10;
  69.       S.WriteBuffer(Buffer, sizeof(Buffer));
  70.     end;
  71.   finally
  72.     S.Free;
  73.   end;
  74. end;
  75.  
  76. procedure TForm1.Button1Click(Sender: TObject);
  77. var
  78.   StartTime : integer;
  79.   EndTime : integer;
  80. begin
  81.   Button1.Enabled := false;
  82.   try
  83.     Label1.Caption := 'creating';
  84.     Label1.Update;
  85.     CreateInputFile;
  86.     Label1.Caption := 'sorting';
  87.     Label1.Update;
  88.     StartTime := GetTickCount;
  89.     aaMergesortFixed('C:\unsorted.dat', 'c:\sorted.dat', MyRecLen, MyCompare);
  90.     EndTime := GetTickCount;
  91.     Label1.Caption := 'done';
  92.   finally
  93.     Button1.Enabled := true;
  94.   end;
  95.   Label2.Caption := IntToStr(EndTime-StartTime);
  96. end;
  97.  
  98. end.
  99.